package com.wc.codeforces.DP.线性DP.New_Rating;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/11/12 17:26
 * @description
 * https://codeforces.com/contest/2029/problem/C
 */
public class Main {
    /**
     * 动态规划:
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 300010;
    // f[i][j][k] 遍历到第 i 个, 第 i 个 跳 j = 1 不跳 j = 0, k 表示1 ~ i 跳 1 没跳 0
    static int[][][] f = new int[N][2][2];
    static int[] a = new int[N];
    static int n;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0){
            n = sc.nextInt();
            for (int i = 0; i <= n; i++){
                for (int j = 0; j < 2; j++) Arrays.fill(f[i][j], -N);
            }
            f[0][0][0] = 0;
            for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
            for (int i = 1; i <= n; i++){
                if (f[i - 1][0][0] < a[i]) f[i][0][0] = f[i - 1][0][0] + 1;
                else if (f[i - 1][0][0] > a[i]) f[i][0][0] = f[i - 1][0][0] - 1;
                else f[i][0][0] = f[i - 1][0][0];

                if (f[i - 1][0][1] < a[i]) f[i][0][1] = f[i - 1][0][1] + 1;
                else if (f[i - 1][0][1] > a[i]) f[i][0][1] = f[i - 1][0][1] - 1;
                else f[i][0][1] = f[i - 1][0][1];

                if (f[i - 1][1][1] < a[i]) f[i][0][1] = Math.max(f[i][0][1], f[i - 1][1][1] + 1);
                else  if (f[i - 1][1][1] > a[i]) f[i][0][1] = Math.max(f[i][0][1], f[i - 1][1][1] - 1);
                else f[i][0][1] = Math.max(f[i][0][1], f[i - 1][1][1]);
                f[i][1][1] = Math.max(f[i - 1][1][1], f[i - 1][0][0]);
            }
            int res = Math.max(f[n][0][1], f[n][1][1]);
            out.println(res);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
